# 作者：要努力，努力，再努力
# 开发时间：2022/4/29 15:33
import time
import os


filename = 'log2.txt'


def show_info():
    num = int(input('1. 退出系统 2. 查看登录日志'))
    return num


def show_log():
    if os.path.exists(filename):
        with open(filename, 'r', encoding='utf-8') as rfile:
            while True:
                log = rfile.readline()
                if log !='':
                    print(str(log),end='')
                else:
                    break
    else:
        print('无登录信息')


def write_log(username):
    try:
        file = open(filename, 'a', encoding='utf-8')
    except:
        file = open(filename, 'w', encoding='utf-8')

    file.write(f'用户名{username},' + '登录时间:' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + '\n')


if __name__ == '__main__':
    username = input('请输入用户名：')
    password = input('请输入密码：')
    if username == 'admin' and password == 'admin':
        write_log(username)
        while True:
            num = show_info()
            if num == 1:
                break
            else:
                show_log()
                continue
    else:
        print('密码不正确')